package servlet;

import entity.FinancingProduct;
import service.FinancingProductService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

@WebServlet("/queryAll")
public class QueryAllServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        FinancingProductService service = new FinancingProductService();
        List<FinancingProduct> products = null;
        try {
            products = service.getAllProducts();
            request.setAttribute("products", products);
            request.getRequestDispatcher("query.jsp").forward(request, response);
        } catch (SQLException e) {
            e.printStackTrace();
            response.sendRedirect("error.jsp");
        }
    }
}
